<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>东莞新华投票系统v1.0</title>
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="css/style.css" />
    <script src="js/jquery.js" type="text/javascript"></script>
    <script src="js/DatePicker.js" type="text/javascript"></script>
    <script src="js/checkinput.js" type="text/javascript"></script>
    <script src="js/ajaxfileupload.js" type="text/javascript"></script>
    <script type="text/javascript">
        function fn(){
            if(checkinput()){
                next_step();
            }else{ return false;}
        }

        function fn2(){
            if(checkinput()){
                addItem();
            }else{ return false;}
        }

        function ajaxFileUpload(){

            $.ajaxFileUpload({
                url:'upload-img.php',
                secureuri: false,
                fileElementId: 'add_img',
                dataType:'json',
                success: function(data,status){
                    $("#upload_img").attr("src",data.path);
                    var src=$("#upload_img").attr("src");
                    $("#del_btn").attr('disabled',false);
                    $("#show_name span").html(data.name);
                },
                error: function(data,status,e){ alert(e);}
            });
        }

        function del_image(){
            var img_path = $("#upload_img").attr("src");
            $.post("del_image.php?action=del_img",{imagepath:img_path},function(msg){
                if(msg==1){
                    $("#show_name span").html("成功删除图片");
                    $("#upload_img").attr("src","images/default.gif");
                }else{  alert(msg);}
            })
        }

        function next_step(){
            var title = $("#sub-title").val();
            var deadDate = $("#dead-date").val();
            var option = $("#sub-option").val();
            var description = $("#description").val();
            $.ajax({
                type:'post',
                url:'add-subvote.php',
                dataType:'json',
                data:{
                    "title":title,
                    "description":description,
                    "option":option,
                    "deadDate":deadDate
                },
                success:function(data){
                    if(data.success==1){
                        $("#step2").show();
                        $("#vsid").val(data.vsid);
                        $("#next_step_btn").attr('disabled','disabled');
                        $("#item-title").addClass("noempty");
                    }else{
                        alert("提交投票主题失败！");
                    }
                },
                error:function(e){
                    alert(e);
                }
            });

        }

        function addItem(){
            var title = $("#item-title").val();
            var vsID   = $("#vsid").val();
            var t_class = $("input:radio:checked").val();
            var viDES  = $("#item-description").val();
            var image = $("#show_name span").html();
            $.ajax({
                type:'post',
                url:'add-item.php',
                dataType:'json',
                data:{"title":title,"vsID":vsID,"class":t_class,"viDES":viDES,"image":image},
                success:function(json){
                    if(json.success==1){
                        alert("添加成功！");
                        $("#item-title,#item-description").val("");
                        $("#upload_img").attr("src","images/default.gif");
                        $("#show_name span").html("默认图片");
                        $("#del_btn").attr('disabled','disabled');
                    }else{
                        alert("添加选项失败！");
                    }

                }
            });
        }
    </script>

</head>
<body id="vote-type1">
<?php
if(!isset($_COOKIE['islogin']) || $_COOKIE['islogin']!=1){
    echo "<script>window.location.href='login.php';</script>";
}
if($_COOKIE['permission']!=1){
    echo "<script>alert('抱歉，你的权限不足。');window.location.href='index.php';</script>";
}

require('config.php')
?>
<div id="nav">
    <div id="nav_top">
        <div class="width navs">
            <div class="logo">
                <a href="index.php" target="ifm"><img src="images/logo.png" width="290" height="54" /></a>
            </div>
            <div class="clear"></div>
        </div>
    </div>
    <div id="header">
        <div class="width">
            <div style="background: url(images/gx.gif) no-repeat; height: 48px;">
                <span style="float: right; font-size: 12px;">欢迎您：<?php echo $_COOKIE["username"];?>---<a href="login.php?action=logout">退出</a></span>
                <div id="top-nav">
                    <a id="1" href="index.php">首页</a>
                    <a id="2" href="my-vote.php" >我的投票</a>
                    <a id="3" href="create-vote.php" class="curr" >创建投票</a>
                    <a id="4" href="manager-vote.php">管理投票</a>
                </div>
            </div>
        </div>
    </div>
</div>
<!--详细内容模块start-->
<div id="content">
    <div id="main-content">
        <form action="add-vote.php" method="post" enctype="multipart/form-data">
            <fieldset id="step1">
                <h3>步骤一：设置基本信息(必填)</h3>
                <div><label for="sub-title">投票标题：</label><input id="sub-title" class="noempty" name="sub-title" type="text" /><span style="color:red;padding-left:30px;font-size:12px;">说明：请输入小于50个字符的标题。</span></div>
                <div><label for="dead-date">截止日期：</label><input id="dead-date" class="noempty" name="dead-date" type="text" onclick="setday(this)" readonly="readonly" /><span style="color:red;padding-left:30px;font-size:12px;">说明：日期必须等于或大于今天。格式例子:2014-9-9</span></div>
                <div><label for="option">投票类型：</label><select id="sub-option"><option value="1" selected>单选</option><option value="2">多选2</option><option value="3">多选3</option><option value="4">多选4</option><option value="5">多选5</option></select></div>
                <div><label style="vertical-align:top;" for="description">投票说明：</label><textarea class="noempty" name="description" id="description" cols="55" rows="5"></textarea><span style="color:red;padding-left:30px;font-size:12px;vertical-align:top;">说明：请输入小于200个字符，内容包括投票目的和规则。</span></div>
                <div><button id="next_step_btn" class="btn btn-warning step-btn" type="button" onclick="fn()">下一步</button></div>
            </fieldset>
            <fieldset id="step2">

                <h3>步骤二：添加投票项</h3>
                <div class="left-content">
                    <div style="margin-left:0;margin-right:0;margin-top:0;" class="width580"><label for="vsid">投票编号：</label><input id="vsid" name="vsid" type="text" readonly="readonly" /></div>
                    <div style="margin-left:0;margin-right:0;" class="width580"><label for="item-title">选项标题：</label><input id="item-title" name="item-title" type="text"><span style="color:red;padding-left:30px;font-size:12px;">(必填)</span></div>
                    <div style="margin-left:0;margin-right:0;margin-top:0;" class="width580"><label for="">选项类型：</label><input id="class1" style="width:50px;border:none;margin:0;padding:0;height:18px;" type="radio" name="t_class" value="后援" />后援 <input id="class2" style="width:50px;border:none;margin:0;padding:0;height:18px;" type="radio" name="t_class" value="前线" />前线</div>
                    <div style="margin-left:0;margin-right:0;" class="width580"><label style="vertical-align:top;" for="item-description">选项描述：</label><textarea name="item-description" id="item-description" cols="55" rows="5"></textarea><span style="color:red;padding-left:30px;font-size:12px;vertical-align:top;">(可选填)</span></div>
                    <div style="margin-left:0;margin-right:0;" class="widht580"><button type="button" class="btn btn-info step-btn" onclick="fn2()" >确定</button></div>
                </div>
                <div class="right-content">
                    <img id="upload_img" style="border:3px dashed #ccc;" width="150px" height="150px" src="images/default.gif" alt="上传图片"  title="上传图片"/>
                    <div style="margin-left:0;margin-right:0">
                        <div style="margin:0;" id="show_name"><span>默认图片</span></div>
                        <div style="margin:0;"><input  style="width:200px;margin-left:20px;border:1px solid #ccc;" type="file" id="add_img" name="add_img" /></div>
                        <div style="margin-top:10px;"><button type="button" class="btn btn-success" onclick="ajaxFileUpload()">上传</button><button id="del_btn" class="btn btn-danger" disabled="disabled" type="button" onclick="del_image()">删除</button></div>
                    </div>
            </fieldset>
        </form>
    </div>
</div>

<!--详细内容模块end-->
<div id="footer" class="clear">
    <div
        style="background: url(images/gx_footer.gif) no-repeat; width: auto; height: 118px; padding: 20px 0 0 0;">
        <div class="width">
            <div style="text-align: center; font-size: 14px;">
                <a href="http://10.44.152.49">东莞新华导航页</a> <a
                    href="http://10.44.152.252./purchase" class="a1" target="ifm">采购立项签报系统</a> <a
                    href="http://10.44.152.166:8080/che/">用车管理系统</a> <a href="http://10.44.152.166:8080/caigou/"
                    >采购随机筛选系统</a>
            </div>
            <div style="margin: 15px 0 0 0; font-size: 11px; text-align: center;">新华人寿保险股份有限公司东莞中心支公司
                版权所有 东莞新华办公室
            </div>
        </div>
    </div>
</div>
</body>
</html>